﻿using System.ComponentModel;
using System.Data.Linq;
using System.Data.Linq.Mapping;

namespace LinkED_WP
{
    public class LinkED_DBHelper : DataContext
    {
        //数据库连接字符串
        public static string DBConnectionString = "Data Source=isostore:/ALLPC.sdf";

        //传递数据库连接字符串给 基类：DataContext
        public LinkED_DBHelper(string ConnectionString) :
            base(ConnectionString)
        {

        }

        //文件表
        public Table<LinkED_PCItem> PCItemTable;
    }

    [Table]
    public class LinkED_PCItem : INotifyPropertyChanged , INotifyPropertyChanging
    {
        //文件编号
        private int _PCID;

        //主键、数据库自动生成、非空
        [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
        public int PCID
        {
            get
            {
                return _PCID;
            }
            set
            {
                if (_PCID != value)
                {
                    NotifyPropertyChanging("PCID");
                    _PCID = value;
                    NotifyPropertyChanged("PCID");
                }
            }
        }

        //文件名称
        private string _IP_Address;

        [Column]
        public string IPAddress
        {
            get
            {
                return _IP_Address;
            }
            set
            {
                if (_IP_Address != value)
                {
                    NotifyPropertyChanging("IPAddress");
                    _IP_Address = value;
                    NotifyPropertyChanged("IPAddress");
                }

            }
        }

        private string _PC_Name;

        [Column]
        public string PCName
        {
            get
            {
                return _PC_Name;
            }
            set
            {
                if (_PC_Name != value)
                {
                    NotifyPropertyChanging("PCName");
                    _PC_Name = value;
                    NotifyPropertyChanged("PCName");
                }

            }
        }

        private bool _TCP;

        [Column]
        public bool TCP
        {
            get
            {
                return _TCP;
            }
            set
            {
                if (_TCP != value)
                {
                    NotifyPropertyChanging("TCP");
                    _TCP = value;
                    NotifyPropertyChanged("TCP");
                }

            }
        }


        // Version column aids update performance.
        [Column(IsVersion = true)]
        private Binary _version;

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

        // Used to notify the page that a data context property changed
        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        #endregion

        #region INotifyPropertyChanging Members

        public event PropertyChangingEventHandler PropertyChanging;

        // Used to notify the data context that a data context property is about to change
        private void NotifyPropertyChanging(string propertyName)
        {
            if (PropertyChanging != null)
            {
                PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
            }
        }

        #endregion
    }
}
